package com.it.gw.modules.user.fragment

import LoginVo
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.it.data.manager.AppCacheManager
import com.it.gw.base.BaseFragment
import com.it.gw.databinding.FragmentHomeBinding
import com.it.gw.modules.station.GwManagerActivity
import com.it.gw.modules.water.activity.ReservoirUploadActivity
import com.it.gw.modules.water.activity.WaterMainActivity
import com.tencent.mmkv.MMKV


class HomeFragment : BaseFragment<FragmentHomeBinding>() {
    companion object {
        const val TAG = "HomeFragment"
    }

    override fun initObserver() {

    }

    override fun initListener() {
        binding.rlWater.setOnClickListener {
            val intent = Intent(requireActivity(), WaterMainActivity::class.java)
            startActivity(intent)
        }
        binding.rlGw.setOnClickListener {
            val intent = Intent(requireActivity(), GwManagerActivity::class.java)
            startActivity(intent)

        }
        binding.rlUpload.setOnClickListener {
            val intent = Intent(requireActivity(), ReservoirUploadActivity::class.java)
            startActivity(intent)

        }

    }

    override fun getView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentHomeBinding.inflate(layoutInflater)
        return binding.root
    }


    override fun initData() {

    }

    override fun initView() {

        val loginVo = MMKV.defaultMMKV()
            .decodeParcelable(AppCacheManager.KEY_LOGIN_DATA, LoginVo::class.java)
        Log.d(TAG, "initView: ${loginVo}")
        binding.name.text = "HI! ${loginVo?.userName}"
        binding.dept.text = "掌上兵团水利"
    }


}